<?php
/**
 * Created by PhpStorm.
 * User: Cui Jun
 * Date: 2016-10-11
 * Time: 9:57
 * To change this template use File | Settings | File Templates.
 */

namespace api\common\controllers;

use yii\helpers\ArrayHelper;
use yii\filters\auth\HttpBasicAuth;
use yii\filters\auth\HttpBearerAuth;
//use yii\filters\auth\QueryParamAuth;
use yii\filters\auth\CompositeAuth;
use yii\filters\RateLimiter;
use api\cs\QueryParamAuth;
class UserController extends CommonController
{
    protected $_is_auth = true; //是否进行登录权限验证

    /*
     * 公共授权验证
     * @return array
     */
    public function behaviors() {
        if($this->_is_auth == true){
            return ArrayHelper::merge(parent::behaviors(), [
                'authenticator' => [
                    #`ComopositeAuth` 混合认证
                    'class' => CompositeAuth::className(),
                    #`authMethods` 中的每一个元素都应该是 一种 认证方式的类或者一个 配置数组
                    'authMethods' => [
                        HttpBasicAuth::className(),// 作为一个用户名被传递
                        HttpBearerAuth::className(),//OAth2.0 协议
                        QueryParamAuth::className(), //在 API URL 中作为一个查询参数被传递
                    ]
                ]
            ]);
        }else{
            return parent::behaviors();
        }
    }

}